﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace JiuZuWuFu.Models
{
    public partial class JackGenealogyJiuZuWuFuContext : DbContext
    {
        public JackGenealogyJiuZuWuFuContext()
        {
        }

        public JackGenealogyJiuZuWuFuContext(DbContextOptions<JackGenealogyJiuZuWuFuContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Pedigree> Pedigree { get; set; }
        public virtual DbSet<RelationTb> RelationTb { get; set; }
        public virtual DbSet<UserTb> UserTb { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=Jack.Genealogy.JiuZuWuFu;User ID=sa;Password=123");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Pedigree>(entity =>
            {
                entity.Property(e => e.PedigreeId).ValueGeneratedNever();

                entity.Property(e => e.PedigreeName).HasMaxLength(50);
            });

            modelBuilder.Entity<RelationTb>(entity =>
            {
                entity.HasKey(e => e.RelationId);
            });

            modelBuilder.Entity<UserTb>(entity =>
            {
                entity.HasKey(e => e.UserId);

                entity.Property(e => e.UserName).HasMaxLength(50);
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
